<?php

namespace App\Http\Controllers\API;

use App\Http\Requests\API\CreateGoodsNumberLogAPIRequest;
use App\Http\Requests\API\UpdateGoodsNumberLogAPIRequest;
use App\Models\GoodsNumberLog;
use App\Repositories\GoodsNumberLogRepository;
use Illuminate\Http\Request;
use App\Http\Controllers\AppBaseController;
use InfyOm\Generator\Criteria\LimitOffsetCriteria;
use Prettus\Repository\Criteria\RequestCriteria;
use Response;

/**
 * Class GoodsNumberLogController
 * @package App\Http\Controllers\API
 */

class GoodsNumberLogAPIController extends AppBaseController
{
    /** @var  GoodsNumberLogRepository */
    private $goodsNumberLogRepository;

    public function __construct(GoodsNumberLogRepository $goodsNumberLogRepo)
    {
        $this->goodsNumberLogRepository = $goodsNumberLogRepo;
    }

    /**
     * Display a listing of the GoodsNumberLog.
     * GET|HEAD /goodsNumberLogs
     *
     * @param Request $request
     * @return Response
     */
    public function index(Request $request)
    {
        $this->goodsNumberLogRepository->pushCriteria(new RequestCriteria($request));
        $this->goodsNumberLogRepository->pushCriteria(new LimitOffsetCriteria($request));
        $goodsNumberLogs = $this->goodsNumberLogRepository->all();

        return $this->sendResponse($goodsNumberLogs->toArray(), 'Goods Number Logs retrieved successfully');
    }

    /**
     * Store a newly created GoodsNumberLog in storage.
     * POST /goodsNumberLogs
     *
     * @param CreateGoodsNumberLogAPIRequest $request
     *
     * @return Response
     */
    public function store(CreateGoodsNumberLogAPIRequest $request)
    {
        $input = $request->all();

        $goodsNumberLogs = $this->goodsNumberLogRepository->create($input);

        return $this->sendResponse($goodsNumberLogs->toArray(), 'Goods Number Log saved successfully');
    }

    /**
     * Display the specified GoodsNumberLog.
     * GET|HEAD /goodsNumberLogs/{id}
     *
     * @param  int $id
     *
     * @return Response
     */
    public function show($id)
    {
        /** @var GoodsNumberLog $goodsNumberLog */
        $goodsNumberLog = $this->goodsNumberLogRepository->findWithoutFail($id);

        if (empty($goodsNumberLog)) {
            return $this->sendError('Goods Number Log not found');
        }

        return $this->sendResponse($goodsNumberLog->toArray(), 'Goods Number Log retrieved successfully');
    }

    /**
     * Update the specified GoodsNumberLog in storage.
     * PUT/PATCH /goodsNumberLogs/{id}
     *
     * @param  int $id
     * @param UpdateGoodsNumberLogAPIRequest $request
     *
     * @return Response
     */
    public function update($id, UpdateGoodsNumberLogAPIRequest $request)
    {
        $input = $request->all();

        /** @var GoodsNumberLog $goodsNumberLog */
        $goodsNumberLog = $this->goodsNumberLogRepository->findWithoutFail($id);

        if (empty($goodsNumberLog)) {
            return $this->sendError('Goods Number Log not found');
        }

        $goodsNumberLog = $this->goodsNumberLogRepository->update($input, $id);

        return $this->sendResponse($goodsNumberLog->toArray(), 'GoodsNumberLog updated successfully');
    }

    /**
     * Remove the specified GoodsNumberLog from storage.
     * DELETE /goodsNumberLogs/{id}
     *
     * @param  int $id
     *
     * @return Response
     */
    public function destroy($id)
    {
        /** @var GoodsNumberLog $goodsNumberLog */
        $goodsNumberLog = $this->goodsNumberLogRepository->findWithoutFail($id);

        if (empty($goodsNumberLog)) {
            return $this->sendError('Goods Number Log not found');
        }

        $goodsNumberLog->delete();

        return $this->sendResponse($id, 'Goods Number Log deleted successfully');
    }
}
